/*
 * @copyright: Huang Ding
 * @Author: ding-cx
 * @Date: 2021-02-24 17:49:09
 * @LastEditors: ding-cx
 * @LastEditTime: 2022-03-28 15:58:59
 * @Description: file content
 */
"use strict";

import * as egg from "egg";
import DingAppWorkerLoader from "./core/loader/DingAppWorkerLoader";
import DingAgentWorkerLoader from "./core/loader/DingAgentWorkerLoader";
import * as path from "path";

import DineggController from "./core/controller/DineggController";
import DineggService from "./core/service/DineggService";
import DineggSubscription from "./core/Subscription/Subscription";
import DineggError from "./core/DineggError";

const EGG_PATH = Symbol.for("egg#eggPath");
const EGG_LOADER = Symbol.for("egg#loader");

class Application extends egg.Application {
	get [EGG_PATH]() {
		return path.dirname(__dirname);
	}

	// 覆盖 Egg 的 Loader，启动时使用这个 Loader
	get [EGG_LOADER]() {
		return DingAppWorkerLoader;
	}
}

class Agent extends egg.Agent {
	get [EGG_PATH]() {
		return path.dirname(__dirname);
	}
	get [EGG_LOADER]() {
		return DingAgentWorkerLoader;
	}
}

export default Object.assign(egg, {
	Application,
	Agent,
	AppWorkerLoader: DingAppWorkerLoader,
	AgentWorkerLoader: DingAgentWorkerLoader,
	Controller: DineggController,
	Service: DineggService,
	Subscription: DineggSubscription,
	DineggError,
});
